package com.ydh.company.controller;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import com.ydh.company.pojo.Condition;
import com.ydh.company.pojo.Opportunity;
import com.ydh.company.utils.UUIDUtil;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("opportunity")
@Api(value = "商机管理接口",tags = "商机管理接口API（3个）HKill")
public class OpportunityController {


    @PostMapping(value = "/queryOpportunityByPage")
    @ResponseBody
    @ApiOperation(value = "1商机列表分页查询接口", notes = "展示初始列表信息", httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败")}
    )
    public ResultData queryOpportunityByPage(@RequestBody @ApiParam(name = "Condition", value = "传入页码和页容量", required = true) Condition condition) {

        Map<String,Object> resultMap = new HashMap<>();

        //获取当前页码
        int currentPage = condition.getCurrentPage();
        //获取页容量
        int perSize = condition.getPerSize();
        System.out.println("当前页码：" + currentPage);
        System.out.println("页容量：" + perSize);

        List<Opportunity> opportunityList = new ArrayList<>();

        Opportunity opportunity1 = new Opportunity();
        opportunity1.setOpportunityId(UUIDUtil.getId());
        opportunity1.setOpportunityCompany("周鸡儿东没责任公司");
        opportunity1.setOpportunityName("周鸡儿东");
        opportunity1.setOpportunityTel("136111");
        opportunity1.setAddress("四川省成都市高新区");
        opportunity1.setOpportunityReason("觉得易订货平台有前景！");
        opportunity1.setOpportunityStatus(0);
        opportunity1.setCreateTime(new Timestamp(System.currentTimeMillis()));

        Opportunity opportunity2 = new Opportunity();
        opportunity2.setOpportunityId(UUIDUtil.getId());
        opportunity2.setOpportunityCompany("周鸡儿东没责任公司");
        opportunity2.setOpportunityName("周鸡儿东");
        opportunity2.setOpportunityTel("136111");
        opportunity2.setAddress("四川省成都市高新区");
        opportunity2.setOpportunityReason("觉得易订货平台有前景！");
        opportunity2.setOpportunityStatus(0);
        opportunity2.setCreateTime(new Timestamp(System.currentTimeMillis()));

        opportunityList.add(opportunity1);
        opportunityList.add(opportunity2);

        resultMap.put("totalPage",21);
        resultMap.put("clientList", opportunityList);

        return ResponseData.success(resultMap);
    }



    @PostMapping(value = "/queryOpportunityByCondition")
    @ResponseBody
    @ApiOperation(value = "2商机列表条件查询接口", notes = "展示条件查询列表信息", httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "查询失败")}
    )
    public ResultData queryClientByCondition(@RequestBody @ApiParam(name = "Condition", value = "输入商机公司名称，进行模糊查询", required = true) Condition condition) {

        Map<String,Object> resultMap = new HashMap<>();

        //获取当前页码
        int currentPage = condition.getCurrentPage();
        //获取页容量
        int perSize = condition.getPerSize();
        //获取输入框的值---公司名称
        String inputValue = condition.getInputValue();

        System.out.println("当前页码：" + currentPage);
        System.out.println("页容量：" + perSize);
        System.out.println("公司名称：" + inputValue);

        List<Opportunity> opportunityList = new ArrayList<>();

        Opportunity opportunity1 = new Opportunity();
        opportunity1.setOpportunityId(UUIDUtil.getId());
        opportunity1.setOpportunityCompany("周鸡儿东没责任公司");
        opportunity1.setOpportunityName("周鸡儿东");
        opportunity1.setOpportunityTel("136111");
        opportunity1.setAddress("四川省成都市高新区");
        opportunity1.setOpportunityReason("觉得易订货平台有前景！");
        opportunity1.setOpportunityStatus(0);
        opportunity1.setCreateTime(new Timestamp(System.currentTimeMillis()));

        Opportunity opportunity2 = new Opportunity();
        opportunity2.setOpportunityId(UUIDUtil.getId());
        opportunity2.setOpportunityCompany("周鸡儿东没责任公司");
        opportunity2.setOpportunityName("周鸡儿东");
        opportunity2.setOpportunityTel("136111");
        opportunity2.setAddress("四川省成都市高新区");
        opportunity2.setOpportunityReason("觉得易订货平台有前景！");
        opportunity2.setOpportunityStatus(0);
        opportunity2.setCreateTime(new Timestamp(System.currentTimeMillis()));

        opportunityList.add(opportunity1);
        opportunityList.add(opportunity2);

        resultMap.put("totalPage",12);
        resultMap.put("clientList", opportunityList);

        return ResponseData.success(resultMap);
    }




    @PostMapping(value = "/updateOpportunityState")
    @ResponseBody
    @ApiOperation(value = "3修改商机状态接口（拒绝）",notes = "通过商机公司名称,修改商机状态",httpMethod = "POST",response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public ResultData updateOpportunityState(@RequestBody @ApiParam(name = "Opportunity",value = "输入商机公司名称（可模糊）和状态（1：通过 2 : 拒绝）",required = true) Opportunity opportunity){

        String opportunityCompany = opportunity.getOpportunityCompany();
        int opportunityStatus = opportunity.getOpportunityStatus();

        System.out.println("商机公司名称：" + opportunityCompany);
        System.out.println("商机状态：" + opportunityStatus);

        int count = 1;
        if (count == 1){
            return ResponseData.success(count);
        }else {
            return ResponseData.error(400,"修改失败");
        }
    }



}
